package com.zdb.mcpserver.Tool;


import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;



@Slf4j
@Service
public class WeatherService {
    private final RestClient restClient;

    public WeatherService() {
        this.restClient = RestClient.builder()
                .baseUrl("https://restapi.amap.com/v3/weather/weatherInfo") // 高德天气API
                .defaultHeader("Accept", "application/json")
                .build();
    }
    @Tool(description = "获取某一城市的天气预报")
    public String getWeatherForecastByLocation(String cityName) {
        String body = restClient.get()
                .uri(uriBuilder -> uriBuilder
                        .queryParam("key", "06af19dc85f9883669e9a59d4e691922")        // 高德API Key
                        .queryParam("city", cityName)    // 城市编码（如北京：110000）
                        .queryParam("extensions", "all") // 获取预报数据
                        .build())
                .retrieve()
                .body(String.class);
        System.out.println(body);
        return body;
    }



}
